﻿using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;
using EntityModels.Entities;

namespace EntityModels.Configures
{
    /// <summary>
    /// 基于配置类的配置
    /// </summary>
    public class SimpleEntityConfiguration : IEntityTypeConfiguration<SimpleEntity>
    {
        public void Configure(EntityTypeBuilder<SimpleEntity> builder)
        {
            builder.ToTable("CustomTableName", "dbo").HasKey(s => s.Id);

            builder.Property(s => s.SimpleEntityId).UseIdentityColumn(1, 1);

            builder.Property(s => s.NullableStruct).HasColumnName("CustomColumnName").HasColumnType("int");

            builder.Property(s => s.Text).IsRequired().HasMaxLength(50);
        }
    }
}
